package com.puao.util;

import com.puao.bean.BallIn;
import com.puao.bean.enumerate.E_TYPE;
import org.apache.commons.beanutils.BeanUtils;

import java.util.*;
import java.util.Map.Entry;

public class InitNum {

    public static List<BallIn> generateNum(List<Integer> input) {
        if (Objects.isNull(input) || input.size() == 0) {
            return null;
        }
        int size = input.size();
        Map<String, String[]> map = null;
        List<BallIn> balls = new ArrayList<>();
        switch (size) {
            case 6:
                map = E_TYPE.getTypeMap(E_TYPE.E_6);
                break;
            case 7:
                map = E_TYPE.getTypeMap(E_TYPE.E_7);
                break;
            case 8:
                map = E_TYPE.getTypeMap(E_TYPE.E_8);
                break;
            case 9:
                map = E_TYPE.getTypeMap(E_TYPE.E_9);
                break;
            case 11:
                map = E_TYPE.getTypeMap(E_TYPE.E_11);
                break;
        }
        if (Objects.nonNull(map)) {
            for (Entry<String, String[]> entry : map.entrySet()) {
                Map<String, Integer> mapNum = new HashMap<>();
                String[] index = entry.getValue();
                int i = 1;
                for (String temp : index) {
                    int num = Integer.valueOf(temp);
                    mapNum.put("red_0" + i, input.get(num));
                    i++;
                }
                try {
                    BallIn ball = new BallIn();
                    BeanUtils.populate(ball, mapNum);
                    balls.add(ball);
                } catch (Exception e) {
                    e.printStackTrace();
                }
//                set.add(list);
            }
        }
        return balls;
    }

    public static List<BallIn> castToBallIn(List<List<String>> args) {
        List<BallIn> balls = new ArrayList<>();
        Map<String, Integer> mapNum = new HashMap<>();
        for (int index = 0; index < args.size(); index++) {
            List<String> temp = args.get(index);
            int i = 1;
            for (int j = 0; j < temp.size(); j++) {
                int num = Integer.valueOf(temp.get(j));
                if(i > 5){
                    mapNum.put("blue_0"+(i- 5),num);
                }else{
                    mapNum.put("red_0" + i, num);
                }
                i++;
            }
            try {
                BallIn ball = new BallIn();
                BeanUtils.populate(ball, mapNum);
                balls.add(ball);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return  balls;
    }


}
